* Analyzing the U.S. studies separately
cd ""
use "coef_wide.dta", clear

* Keeping only studies of the US
keep if us==1

* Table E2
* HL
meologit HL_7 global i.issue influence i.party  distance_HL ln_n pre_diff_HL if p_HL_10==1 || study:
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)') sortvar(us influence  party global issue distance_HL distance_HM ln_n) lab replace

* HM
meologit HM_7 global i.issue influence i.party  distance_HM ln_n pre_diff_HM if p_HM_10==1 || study:
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)') sortvar(us influence  party global issue distance_HL distance_HM ln_n) lab append

* ambiguous cases
melogit rescale_p_HL_10 global i.issue i.party influence  distance_HL  ln_n pre_diff_HL || study:
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)') sortvar(us influence  party global issue distance_HL distance_HM ln_n) lab append

melogit rescale_p_HM_10 global i.issue i.party influence  distance_HM  ln_n pre_diff_HM || study:
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)') sortvar(us influence  party global issue distance_HL distance_HM ln_n) lab append


* Figures E3-E4. 
**** calculated predicted probabilities to graph - this code is for the high vs low comparison
use "coef_wide.dta", clear
keep if us==1

meologit HL_7 global i.issue influence i.party distance_HL ln_n pre_diff_HL if p_HL_10==1 || study:
predict pr* if e(sample)
keep if e(sample)

* Global
preserve
keep pr1-pr7 global
foreach v of varlist pr1-pr7 {
bysort global: egen re_`v'=mean(`v')
}

label define yesno_gl  0 "No" 1 "Yes"
label values global yesno_gl


keep global re_*
duplicates drop re_pr1, force
reshape long re_pr, i(global) j(HL_7)

ren global lab
decode lab, g(re_lab)
g byvar="General political ideology"


save "prpHL_global_US.dta", replace
restore

* issue
preserve
keep pr1-pr7 issue
foreach v of varlist pr1-pr7 {
bysort issue: egen re_`v'=mean(`v')
}

keep issue re_*
duplicates drop re_pr1, force
reshape long re_pr, i(issue) j(HL_7)

ren issue lab
decode lab, g(re_lab)
g byvar="Issue"

save "prpHL_issue_US.dta", replace
restore


* Influence
preserve
keep pr1-pr7 influence
foreach v of varlist pr1-pr7 {
bysort influence: egen re_`v'=mean(`v')
}

keep influence re_*
duplicates drop re_pr1, force
reshape long re_pr, i(influence) j(HL_7)

ren influence lab
decode lab, g(re_lab)
g byvar="N of groups included in a model"

save "prpHL_influence_US.dta", replace
restore

* Partisanship
preserve
keep pr1-pr7 party
foreach v of varlist pr1-pr7 {
bysort party: egen re_`v'=mean(`v')
}

keep party re_*
duplicates drop re_pr1, force
reshape long re_pr, i(party) j(HL_7)

ren party lab
decode lab, g(re_lab)
g byvar="Partisanship"

save "prpHL_party_US.dta", replace
restore

use "prpHL_global_US.dta", clear
append using "prpHL_issue_US.dta"
append using "prpHL_influence_US.dta"
append using "prpHL_party_US.dta"

g id=1 if byvar=="N of groups included in a model"
replace id=2 if byvar=="Partisanship"
replace id=3 if byvar=="General political ideology"
replace id=4 if byvar=="Issue"

label values lab .

save "prpHL_all_US.dta", replace


**** calculated predicted probabilities to graph - this code is for the high vs middle comparison
use "coef_wide.dta", clear
keep if us==1


meologit HM_7 global i.issue influence i.party distance_HM ln_n pre_diff_HM if p_HM_10==1 || study:
predict HMpr* if e(sample)
keep if e(sample)


* global
preserve
keep HMpr1-HMpr7 global
foreach v of varlist HMpr1-HMpr7 {
bysort global: egen re_`v'=mean(`v')
}

label define yesno_gl  0 "No" 1 "Yes"
label values global yesno_gl

keep global re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(global) j(HM_7)
ren global lab
decode lab, g(re_lab)
g byvar="General political ideology"

save "prpHM_global_US.dta", replace
restore

* issue
preserve
keep HMpr1-HMpr7 issue
foreach v of varlist HMpr1-HMpr7 {
bysort issue: egen re_`v'=mean(`v')
}

keep issue re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(issue) j(HM_7)

ren issue lab
decode lab, g(re_lab)
g byvar="Issue"

save "prpHM_issue_US.dta", replace
restore

* Influence
preserve
keep HMpr1-HMpr7 influence
foreach v of varlist HMpr1-HMpr7 {
bysort influence: egen re_`v'=mean(`v')
}

keep influence re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(influence) j(HM_7)

ren influence lab
decode lab, g(re_lab)
g byvar="N of groups included in a model"


save "prpHM_influence_US.dta", replace
restore

* party
preserve
keep HMpr1-HMpr7 party
foreach v of varlist HMpr1-HMpr7 {
bysort party: egen re_`v'=mean(`v')
}

keep party re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(party) j(HM_7)

ren party lab
decode lab, g(re_lab)
g byvar="Partisanship"

save "prpHM_party_US.dta", replace
restore

*** combining all estimates in one dataset

use "prpHM_issue_US.dta", clear
append using "prpHM_global_US.dta"
append using "prpHM_influence_US.dta"
append using "prpHM_party_US.dta"

g id=1 if byvar=="N of groups included in a model"
replace id=2 if byvar=="Partisanship"
replace id=3 if byvar=="General political ideology"
replace id=4 if byvar=="Issue"

label values lab .

save "prpHM_all_US.dta", replace
